import { isLogined } from '../api/index'

export async function checkLoginStatus() {
  const token = localStorage.getItem("AUTO_TOKEN")
  if (!token) {
    console.log('登录状态检查: 未找到token')
    return false
  }

  try {
    const resData = await isLogined({ token })
    console.log('登录状态检查响应:', resData)

    if (resData && (resData.code === 200 || resData.msg === '用户登录在线状态')) {
      return true
    }
    return false
  } catch (error) {
    console.error('登录状态检查失败:', error)
    return false
  }
}

export async function requireLogin() {
  const isLoggedIn = await checkLoginStatus()
  return isLoggedIn
}

